/*
 *      keybindingsdialog.h
 *
 *      Copyright 2011 David Vachulka <david@konstrukce-cad.com>
 *      Copyright Roland Baudin <roland65@free.fr>
 *
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 3 of the License, or
 *      (at your option) any later version.
 *
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 */

#ifndef KEYBINDINGSDIALOG_H
#define KEYBINDINGSDIALOG_H

#include "defs.h"
#include "fxext.h"

class BindingsDialog : public FXDialogBox
{
    FXDECLARE(BindingsDialog)
protected:
    FXLabel *keylabel;
private:
    BindingsDialog()
    {
        ;
    }
public:
    BindingsDialog(FXWindow *win, FXString input, FXString message, FXString title, FXIcon *icon=NULL);
    virtual void create();
    long onCmdKeyPress(FXObject*,FXSelector,void*);
    FXString getKey()
    {
        return keylabel->getText();
    }
};

class KeybindingsDialog: public FXDialogBox
{
    FXDECLARE(KeybindingsDialog)
public:
    KeybindingsDialog(FXWindow *owner);
    virtual ~KeybindingsDialog();

    virtual void create();

    long onCancel(FXObject*,FXSelector,void*);
    long onSaveClose(FXObject*,FXSelector,void*);
    long onKBList(FXObject*,FXSelector,void*);
    long onKeyPress(FXObject*,FXSelector,void*);
    static FXint compareSection(const FXchar *p, const FXchar *q, FXint s);
    static FXint ascendingActionName(const FXIconItem *a, const FXIconItem *b);
    static FXint descendingActionName(const FXIconItem *a, const FXIconItem *b);
    static FXint ascendingKeybinding(const FXIconItem *a, const FXIconItem *b);
    static FXint descendingKeybinding(const FXIconItem *a, const FXIconItem *b);
private:
    KeybindingsDialog() {}
    KeybindingsDialog(const KeybindingsDialog& orig);

    FXVerticalFrame *m_contents, *m_tableframe;
    FXHorizontalFrame *m_buttonframe;
    FXIconList *m_list;
    dxEXButton *m_buttonCancel, *m_buttonSaveClose;
    dxStringMap m_keybindings;
    FXbool m_changed;
    dxStringArray m_nonchangeableBindings;

    FXbool bindingExist(const FXString &key, const FXString &kb);
    void updateList();
};

#endif  /* KEYBINDINGSDIALOG_H */

